//
//  RemindView.swift
//  TLCLockDemo
//
//  Created by run on 2024/7/23.
//

import SwiftUI
import TLCLock

struct RemindView: View {


    let device: LockDevice

    var body: some View {
        VStack {
            YxrActionView(
                data: [
                    (0, "关闭"),
                    (1, "提前1天"),
                    (2, "提前2天"),
                    (3, "提前3天"),
                    (4, "提前4天"),
                    (5, "提前5天"),
                    (6, "提前6天"),
                    (7, "提前7天"),
                ], column: 3,
                itemBuilder: { value in
                    YXRActionItem(text: value.1) {
                        switch value.0 {
                        case 0: expireReminder(day: .close)
                        case 1: expireReminder(day: .oneDay)
                        case 2: expireReminder(day: .towDay)
                        case 3: expireReminder(day: .threeDay)
                        case 4: expireReminder(day: .fourDay)
                        case 5: expireReminder(day: .fiveDay)
                        case 6: expireReminder(day: .sixDay)
                        case 7: expireReminder(day: .sevenDay)
                        default:
                            print("未实现的方法")
                        }
                    }
                }
            )
            .padding(.horizontal, 10)
            
            LogView()
        }
        .yxrNavigationTitle("过期提醒")
    }

    func expireReminder(day: ExpireReminderType) {
        guard let lockKey = Server.getSecret(device.macAddress) else {
            showToast("没有lockKey")
            return
        }

        lockTask(desc: "过期提醒") {
            await device.expireReminder(day: day, lockKey: lockKey, trackId: Server.testTrackId)
        }
    }
}
